﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using TRPOP.CRM.Component.Model;
using TRPOP.CRM.Component.DALSQLServer;
using TRPOP.CRM.Component.Common;
using TRPOP.Common;

namespace TRPOP.CRM.Component.Business
{
    /// <summary>
    /// 部门信息管理
    /// </summary>
    public class DepartmentManage
    {
        /// <summary>
        /// 根据ID获取DepartmentInfo
        /// </summary>
        /// <param name="intID"></param>
        /// <returns></returns>
        public static DepartmentInfo GetDepartmentById(int intID)
        {
            return new DepartmentDAL().GetInfoById(intID);
        }

        /// <summary>
        /// 保存部门信息
        /// </summary>
        /// <param name="oSaveDepartment"></param>
        /// <returns></returns>
        public static bool SaveDepartment(DepartmentInfo oSaveDepartment)
        {
            return new DepartmentDAL().Save(oSaveDepartment);
        }

        /// <summary>
        /// 获取树形结构的 部门信息
        /// </summary>
        /// <param name="intParentId"></param>
        /// <param name="strCondition"></param>
        /// <returns></returns>
        public static List<DepartmentLevel> GetAllDepartmentTree(int intParentId, string strCondition)
        {

            List<DepartmentLevel> oListTree = DepartmentDAL.GetListTree(intParentId, -1, strCondition);
            
            foreach (DepartmentLevel oDepartmentInfoLevel in oListTree)
            {
                oDepartmentInfoLevel.nvcDepartmentName = SystemConst.TreeLevel.Repeat(oDepartmentInfoLevel.iLevel) + oDepartmentInfoLevel.nvcDepartmentName;
            }

            return oListTree;
        }
    }
}
